package cn.usian.jyzx.product.service.impl;

import cn.usian.jyzx.model.constant.Constant;
import cn.usian.jyzx.model.entity.product.Brand;
import cn.usian.jyzx.model.vo.common.Result;
import cn.usian.jyzx.model.vo.common.ResultCodeEnum;
import cn.usian.jyzx.product.mapper.BrandMapper;
import cn.usian.jyzx.product.service.BrandService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    BrandMapper brandMapper;
    @Autowired
    RedisTemplate redisTemplate;
    @Override
    public List<Brand> findall() {
        String brand = (String) redisTemplate.opsForValue().get(Constant.BRAND);
        if (brand == null){
            List<Brand> brandList = brandMapper.findall();
            redisTemplate.opsForValue().set(Constant.BRAND, JSONObject.toJSONString(brandList));
           return brandList;
    }
            List<Brand> brandList = JSON.parseArray(brand, Brand.class);
            return brandList;

    }
}
